package resources.student;

import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

import model.student.Group;
import dao.Linker;
import dao.StudentDAO;

public class GroupRes 
{
	@Context
	UriInfo uriInfo;
	
	@Context
	Request request;
	
	String groupId;
	
	public GroupRes(UriInfo uriInfo, Request request, String groupId) 
	{
		this.uriInfo = uriInfo;
		this.request = request;
		this.groupId = groupId;
	}
	
	@GET
	@Produces(MediaType.TEXT_XML)
	public Group getDataBrowser() 
	{
		Linker.sort();
		
		Group group = StudentDAO.getGroupsCP().get(groupId);
		
		if(group == null)
			throw new RuntimeException("Get: Group with " + groupId +  " not found");
		return group;
	}
	
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public Group getDataBrowserJSON() 
	{
		return getDataBrowser(); 
	}
	
	@GET
	@Produces(MediaType.APPLICATION_XHTML_XML)
	public Group getDataBrowserXHTML() 
	{
		return getDataBrowser(); 
	}
	
	@GET
	@Produces(MediaType.APPLICATION_XML)
	public Group getDataBrowserXML() 
	{
		return getDataBrowser(); 
	}
}